import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service


class MyTestCaseFireFox(unittest.TestCase):
    driver = None

    @classmethod
    def setUpClass(cls) -> None:
        # 注册 驱动打开的位置
        service = Service(executable_path="../../dirver_exe/geckodriver.exe")
        # 打开浏览器  driver 代表 浏览器对象
        cls.driver = webdriver.Firefox(service=service)

    def test_baidu(self):
        self.driver.get("https://112.80.248.76:443/")

        # 元素 定位 的 一种方式  xpath
        text = self.driver.find_element(by=By.XPATH, value="//input[@id='kw']")
        text.send_keys('selenium')

        button = self.driver.find_element(By.CSS_SELECTOR, "input[id='su']")
        button.click()


    # @classmethod
    # def tearDownClass(cls) -> None:
    #     cls.driver.close()  # 只会关闭一个标签页
    #     # cls.driver.quit()  # 直接退出浏览器 并且关闭所有的标签页


if __name__ == '__main__':
    unittest.main()
